package com.stlm2.controller;

import com.stlm2.dems.service.DdmObligationService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/ddmObligationC")
public class DdmObligationController {
    @Resource
    private DdmObligationService ddmObligationService;
    /*zlq
* crm查询服务承诺列表页面
* */
    @RequestMapping(value="/listView",produces="application/json;charset=UTF-8")
    public ModelAndView listView(ModelAndView modelAndView){
        modelAndView.setViewName("/ddmObligation/list");
        return modelAndView;
    }
    /*
    *查询服务承诺名称
    * zlq
     */
    @ResponseBody
    @RequestMapping(value="/getDdmObligation.json",produces="application/json;charset=UTF-8")
    public  String getDdmObligation(ModelMap model){
        String data=null;
        try {
            data=ddmObligationService.getDdmObligation(model);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
 *添加服务承诺
 * zlq
 * token:
 * name:名称
 * label：标签
 * detailsUrl：详情路径
  */
    @ResponseBody
    @RequestMapping(value="/add.json",produces="application/json;charset=UTF-8")
    public  String add(ModelMap model, String token,String name,String label,String imgUrl,String details){
        String data=null;
        try {
            data=ddmObligationService.add(model,token,name,label,imgUrl,details);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    @ResponseBody
    @RequestMapping(value="/getList.json",produces="application/json;charset=UTF-8")
    public  String getList(ModelMap model,String token ,String page){
        String data=null;
        try {
            data=ddmObligationService.getList(model,token,page);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

}
